#include "main.h"

#include "bitmaps/new.xpm"
#include "bitmaps/open.xpm"

IMPLEMENT_APP(UKeyApp)

UKeyFrame::UKeyFrame(wxWindow *parent,
					 const wxWindowID id,
					 const wxString& title,
					 const wxPoint& pos,
					 const wxSize& size,
					 const long style)
	: wxFrame(parent, id, title, pos, size, style | wxNO_FULL_REPAINT_ON_RESIZE)
{
	wxPanel *panel = new wxPanel(this, wxID_ANY);
	wxButton *button = new wxButton(panel, wxID_EXIT, wxT("Quit"), wxPoint(20,20));
	Connect(wxID_EXIT, wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(UKeyFrame::OnQuit));
	button->SetFocus();
	Centre();
}

UKeyFrame::~UKeyFrame()
{
}

void UKeyFrame::OnQuit(wxCommandEvent & WXUNUSED(event))
{
	Close(true);
}

bool UKeyApp::OnInit()
{
	UKeyFrame *uKeyFrame = new UKeyFrame((wxFrame *)NULL, wxID_ANY, wxT("uKey Cipher"),
										  wxDefaultPosition, wxSize(500,400),
										  wxCLOSE_BOX|wxMINIMIZE_BOX|wxCAPTION|wxSYSTEM_MENU);
	uKeyFrame->SetIcon(wxICON(mondrian));
	uKeyFrame->CreateStatusBar();

	// create menubar
	wxMenu *file_menu = new wxMenu;
	file_menu->Append(wxID_OPEN, wxT("&Open...\tCtrl+O"),wxT("Open a file"));
	file_menu->Append(wxID_EXIT, wxT("&Exit"),wxT("Exit uKey Cipher"));
	wxMenu *help_menu = new wxMenu;

	wxMenuBar *menu_bar = new wxMenuBar;
	menu_bar->Append(file_menu, wxT("&File"));
	menu_bar->Append(help_menu, wxT("&Help"));
	uKeyFrame->SetMenuBar(menu_bar);

	// create toolbar
	wxToolBar *toolbar = uKeyFrame->CreateToolBar();
	wxBitmap bitmaps[2];
	bitmaps[0] = wxBitmap(new_xpm);
	bitmaps[1] = wxBitmap(open_xpm);
	toolbar->AddTool(0, _T("New"),bitmaps[0],_T("New file"));
	toolbar->AddTool(1, _T("Open"),bitmaps[1],_T("Open file"));
	toolbar->AddSeparator();
	toolbar->Realize();

	uKeyFrame->Show(true);
	return true;
}